﻿using AdminSystem.Application.Commands.TraceabilityCommands;
using AdminSystem.Domain.Entities;
using AdminSystem.EntityFramworkCore;
using AdminSystem.Repositories.Interfaces;
using AutoMapper;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminSystem.Application.CommandHandlers.TraceabilityCommandHandlers
{
    public class TraceabilityDelCommandHandler : IRequestHandler<TraceabilityDelCommand, APIResult<object>>
    {
        private readonly IBaseRepositories<Traceability> traceabilityBase;
        private readonly IMapper mapper;
        public TraceabilityDelCommandHandler(IBaseRepositories<Traceability> traceabilityBase, IMapper mapper)
        {
            this.traceabilityBase = traceabilityBase;
            this.mapper = mapper;
        }
        public Task<APIResult<object>> Handle(TraceabilityDelCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = ResultCode.删除成功;
            result.Message = ResultCode.删除成功.ToString();
            var entity = mapper.Map<Traceability>(request);
            entity.IsDelete = true;
            int i = traceabilityBase.Update(entity).Result;
            
            return Task.FromResult(result);

        }
    }
}
